package com.io.example.demoparent.ES.es;


import com.io.example.demoparent.ES.util.ESUtil;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.GetIndexRequest;
import org.elasticsearch.client.indices.GetIndexResponse;
import org.elasticsearch.cluster.metadata.AliasMetaData;
import org.elasticsearch.cluster.metadata.MappingMetaData;
import org.elasticsearch.common.settings.Settings;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/*
    查询索引信息
 */
public class ES_Index_Search {

    public static void main(String[] args) throws IOException {
        RestHighLevelClient restHighLevelClient = ESUtil.esRestClient( );
        GetIndexRequest getIndexRequest = new GetIndexRequest( "user");
        GetIndexResponse getIndexResponse = restHighLevelClient.indices( ).get(getIndexRequest, RequestOptions.DEFAULT);
        Map<String, List<AliasMetaData>> aliases = getIndexResponse.getAliases( );
        System.out.println("aliases = " + aliases);
        Map<String, MappingMetaData> mappings = getIndexResponse.getMappings( );
        System.out.println("mappings = " + mappings);
        Map<String, Settings> settings = getIndexResponse.getSettings( );
        System.out.println("settings = " + settings);

        mappings.forEach((key,valeus)->{
            System.out.println("key = " + key);
            System.out.println("valeus = " + valeus);
            Map<String, Object> sourceAsMap = valeus.getSourceAsMap( );
            sourceAsMap.forEach((k,v)->{
                System.out.println("k = " + k);
                System.out.println("v = " + v);

            });
        });


        restHighLevelClient.close();
    }
}
